<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script type="text/javascript" src="../js/jquery-3.3.1.min.js"></script>
</head>
<body>
公司名称；
<select name="" id="company" onchange="changeCompany()">

</select>
公司部门:
<select name="" id="department" onchange="changeDepartment()">

</select>
公司员工:
<select name="" id="staff">

</select>
</body>
</html>
<script type="text/javascript">
    $(function () {
        $.ajax({
            url:"../json/dataCompany.json",
            type:"get",
            data:"",
            dataType:"json",
            success:function (data) {
                var html = '<option value="-1">--请选择公司--</option>'
                $.each(data,function (a,b) {
                    if(b.type == '1'){
                        html += '<option value="'+b.id+'">'+b.name+'</option>'
                    }
                })
                $("#company").append(html)
            },
            error:function () {
                alert("请求失败！")
            }
        });
    });
    //公司找部门
    function changeCompany() {
        $("#department").empty();
        var id = $("#company option:selected").val();
        if (id != '-1'){
        $.ajax({
            url:"../json/dataCompany.json",
            type:"get",
            data:"",
            dataType:"json",
            success:function (data) {
                var html = '<option value="-1">--请选择部门--</option>'
                $.each(data,function (a,b) {
                    if(id == b.p_id){
                        html += '<option value="'+b.id+'">'+b.name+'</option>'
                    }
                })
                $("#department").append(html)
            },
            error:function () {
                alert("部门请求失败！")
            }
        });
        }
    }
    //部门找员工
    function changeDepartment() {
        $("#staff").empty();
        var id = $("#department option:selected").val();
        if (id != '-1'){
            $.ajax({
                url:"../json/dataCompany.json",
                type:"get",
                data:"",
                dataType:"json",
                success:function (data) {
                    var html = '<option value="-1">--请选择员工--</option>'
                    $.each(data,function (a,b) {
                        if(id == b.p_id){
                            html +='<option value="'+b.id+'">'+b.name+'</option>'
                        }
                    });
                    $("#staff").append(html);
                },
                error:function () {
                    alert("员工请求失败")
                }
            });
        }
    }
</script>